<?php
/**
 * Created by PhpStorm.
 * User: LEO
 * Date: 25/10/17
 * Time: 5:04 PM
 */

namespace App\Http\API;

use App\Http\Controllers\Controller as LaravelController;
class ApiController extends LaravelController{

    public function success($code,$data=[], $message='request success',$status=200)
    {

        return response()->json(['code' => $code,'data'=>$data,'message'=>$message],$status)
            ->header('Access-Control-Allow-Origin',env('Access-Control-Allow-Origin'))
            ->header('Access-Control-Allow-Headers', 'x-requested-with,content-type,accept,origin,authorization,x-csrftoken,X-XSRF-TOKEN')
            ->header('Access-Control-Allow-Methods', 'GET, POST, PATCH, PUT, DELETE,OPTIONS')
            ->header('Access-Control-Allow-Credentials', 'true');
    }

    public function fail($code,$data=[], $message='request failed',$status = 200)
    {
        return response()->json(['code' => $code,''=>false,'data'=>$data, 'message'=>$message],$status)
            ->header('Access-Control-Allow-Origin',env('Access-Control-Allow-Origin'))
            ->header('Access-Control-Allow-Headers', 'x-requested-with,content-type,accept,origin,authorization,x-csrftoken,X-XSRF-TOKEN')
            ->header('Access-Control-Allow-Methods', 'GET, POST, PATCH, PUT, DELETE,OPTIONS')
            ->header('Access-Control-Allow-Credentials', 'true');
    }
}